package com.yfbao.web.pdf.controller;

import com.yfbao.web.pdf.controller.vo.ApiResponse;
import com.yfbao.web.pdf.dto.ModificationDto;
import com.yfbao.web.pdf.dto.ModificationRequestDto;
import com.yfbao.web.pdf.service.ModificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/pdf")
public class PdfFileController {


    @Autowired
    private ModificationService modificationService;

    @PostMapping("/modify")
    public ResponseEntity<ApiResponse<String>> modifyDocument(
             @RequestBody ModificationRequestDto request) {
        try {
            modificationService.applyModifications(request);
            return ResponseEntity.ok(ApiResponse.success("文档修改成功"));
        } catch (Exception e) {
            return ResponseEntity.badRequest()
                    .body(ApiResponse.error(e.getMessage()));
        }
    }

    @GetMapping("/modifications/{page}")
    public ResponseEntity<ApiResponse<List<ModificationDto>>> getModifications(
            @PathVariable Integer page) {
        List<ModificationDto> modifications = modificationService.getModificationsByPage(page);
        return ResponseEntity.ok(ApiResponse.success(modifications));
    }

}
